package com.code516.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.code516.dao.StudentDao;
import com.code516.entity.StudentEntity;
import com.code516.service.StudentService;
import com.code516.util.GradeStatus;

@Service
public class StudentServiceImpl implements StudentService{

	@Resource
	private StudentDao studentDao;
	
	/**
	 * �����ֻ���ѯ�û��Ƿ����
	 * @param stuMobile
	 * @return
	 */
	public StudentEntity findByMobile(String stuMobile){
		StudentEntity studentEntity = null;
		try {
			studentEntity = studentDao.findByMobile(stuMobile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return studentEntity;
	}
	
	
	/**
	 * ѧ��ע��
	 * @param stuMobile
	 * @param password
	 * @param phoneYzm
	 * @return
	 */
	public int saveStudent(String stuMobile, String password){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		StudentEntity studentEntity = new StudentEntity();
		studentEntity.setNickname(GradeStatus.loadNickname());
		//��ʼͷ��
		studentEntity.setStuTitle(GradeStatus.title(0));
		studentEntity.setStuMobile(stuMobile);
		studentEntity.setStuPass(password);
		studentEntity.setStuAddtime(sdf.format(new Date()));
		try {
			studentDao.saveStudent(studentEntity);
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		return 1;
	}
	
	
	/**
	 * �޸�ѧ����¼����
	 * @param stuMobile
	 * @param password
	 * @return
	 */
	public int updatePass(String stuMobile, String password){
		try {
			studentDao.updatePass(stuMobile,password);
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		return 1;
	}
	
	
	/**
	 * ��������
	 * ѧ���޸��Լ�������Ϣ
	 * @param studentEntity
	 * @return
	 */
	public int saveUpdateStudent(StudentEntity studentEntity){
		try {
			studentDao.saveUpdateStudent(studentEntity);
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		return 1;
	}
	
	
	public StudentEntity findById(int stuId){
		StudentEntity studentEntity = null;
		try {
			studentEntity = studentDao.findById(stuId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return studentEntity;
	}
	
}
